package cn.yunhe.services;

import cn.yunhe.dao.AddOrderDao;
import cn.yunhe.entity.OrderCon;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.Map;

public class OrderAddService {
    SqlSession sqlSession=null;
    AddOrderDao addOrderDao=null;
    public void addOrder(OrderCon orderCon){
        try {
            sqlSession=SqlSessionFactoryUtil.getSqlSession();
            addOrderDao=sqlSession.getMapper(AddOrderDao.class);
            Map map=new HashMap();
            map.put("oid",orderCon.getOrder().getOid());
            map.put("uid",orderCon.getOrder().getUserData().getUserAccount().getUid());
            map.put("mid",orderCon.getOrder().getMerData().getMerAccount().getMid());
            map.put("totalPrice",orderCon.getOrder().getTotalPrice());
            map.put("createDate",orderCon.getOrder().getCreateDate());
            map.put("flag",orderCon.getOrder().getFlag());
            map.put("address",orderCon.getOrder().getAddress());

            Map map1=new HashMap();
            map1.put("fid",orderCon.getFood().getFid());
            map1.put("count",orderCon.getCount());
            map1.put("oid",orderCon.getOrder().getOid());


            addOrderDao.addOrder(map);
            addOrderDao.addOrderCon(map1);
            sqlSession.commit();
        }finally {
            sqlSession.close();
        }

    }
}
